remove extra space in string js

81

remove extra space in string js -

newString = string.replace(/\s+/g,' ').trim();

js method string remove extra spaces -

const sentence = '    My string with a    lot   of Whitespace.  '.replace(/\s+/g, ' ').trim()

// 'My string with a lot of Whitespace.'

Comments

Submit
0 Comments